package com.my.test.thread.thread;

public class MyThread extends Thread{


    private static int count = 5;

    private static Object obj = new Object();

    @Override
    public void run(){
        while (count > 0) {
            System.out.println(obj);
            count--;
            System.out.println(Thread.currentThread().getName()+":"+count);
        }
    }

    /**
     *
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        // 当count声名为普通变量时候线程各自占有
        // 当count声名为static变量时线程共享
        // obj声名为普通变量每次都会初始化一个obj
        new MyThread().start();
        new MyThread().start();
        new MyThread().start();
        new MyThread().start();
        new MyThread().start();


    }
}
